package edu.scau.mis.pos.service.impl;

import edu.scau.mis.pos.entity.PosCategory;
import edu.scau.mis.pos.mapper.CategoryMapper;
import edu.scau.mis.pos.mapper.PosItemMapper;
import edu.scau.mis.pos.mapper.PosOrderItemMapper;
import edu.scau.mis.pos.service.ICategoryService;
import edu.scau.mis.pos.vo.CategoryVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * (LabType)表服务实现类
 */
@Service("categoryService")
public class CategoryServiceImpl implements ICategoryService {
    @Autowired
    private CategoryMapper categoryMapper;

    @Autowired
    private PosItemMapper posItemMapper;

    @Autowired
    private PosOrderItemMapper posOrderItemMapper;

    /**
     * 通过ID查询单条数据
     *
     * @param typeId 主键
     * @return 实例对象
     */
    @Override
    public PosCategory queryById(Integer typeId) {
        return this.categoryMapper.queryById(typeId);
    }

    /**
     * 查询指定行数据
     *
     * @param posCategory 筛选条件
     * @return 查询结果
     */
    @Override
    public List<PosCategory> queryAll(PosCategory posCategory) {
        return this.categoryMapper.queryAll(posCategory);
    }

    /**
     * 新增数据
     * @param posCategory 实例对象
     */
    @Override
    public void insert(PosCategory posCategory) {
        this.categoryMapper.insert(posCategory);
    }

    /**
     * 修改数据
     *
     * @param posCategory 实例对象
     */
    @Override
    public void update(PosCategory posCategory) {
        this.categoryMapper.update(posCategory);
    }

    /**
     * 通过主键删除数据
     *
     * @param typeId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer typeId) {
        return this.categoryMapper.deleteById(typeId) > 0;
    }

    /**
     * 查询产品销量
     *
     * @return
     */
    @Override
    public List<CategoryVo> totalSalesAmountByCategory(){
        return this.categoryMapper.querySalesVolume();
    }
}
